//
//  LKPushSetModel.m
//  LKIntelligentVideoProject
//
//  Created by she1323 on 2018/11/13.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKPushSetModel.h"
#import "LKPushModel.h"
#import "LKMapViewController.h"
@implementation LKPushSetModel


+ (void)pushWithInfo:(NSDictionary *)info
{
    NSLog(@"我是推送过来的=%@",info);
//    LKPushModel *model = [LKPushModel modelWithDictionary:info];
    NSDictionary *param = [LKPushSetModel dictionaryWithJsonString:info[@"extra_key"]];
    UITabBarController *t = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    LKMapViewController *con = [[LKMapViewController alloc] init];
    CLLocationCoordinate2D pt = CLLocationCoordinate2DMake([param[@"unitLatitude"] doubleValue], [param[@"unitLongitude"] doubleValue]);
    con.pt = pt;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [(UINavigationController *)t.selectedViewController pushViewController:con animated:YES];
    });
    
}
//json字符串转化为字典
+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString
{
    if (jsonString == nil) {
        return nil;
    }
    
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:&err];
    if(err)
    {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}
+ (UIViewController *)controllerWithIndex:(NSInteger)index
{
    UITabBarController *t = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    t.selectedIndex = index;
    
    UINavigationController *nav =  (UINavigationController *)t.viewControllers[1];
    [nav popToRootViewControllerAnimated:NO];
    
    return nav.viewControllers.firstObject;
}

+ (void)setNewTagsWithInfo:(NSDictionary *)info
{
    LKPushModel *model = [LKPushModel modelWithDictionary:info];
    
    if (model.ContentType == 1 || model.ContentType == -1) {
        
        [JPUSHService cleanTags:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
            
        } seq:1];
        
        [JPUSHService setTags:[NSSet setWithObject:model.Content] completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
            
        } seq:1];
    }
    
}

+ (void)setUpMyPushInfo
{
    LKUserInfor *account = [LKUserInforTool account];
//    if (!account.roleId || !account.tagAnd) {
//        return;
//    }
    if (!account.roleId) {
        return;
    }
    if (account) {
//        [JPUSHService setAlias:account.roleId completion:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
//
//        } seq:2];
        
        [JPUSHService setTags:[NSSet setWithObject:account.roleId] completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
            
        } seq:1];
    }
    
}

+ (void)clearPushInfo
{
    [JPUSHService cleanTags:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
        
    } seq:1];
//    [JPUSHService deleteAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
//
//    } seq:2];
    
}



@end
